﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using CSP.Dao.CommonDao;
using CSP.Dao.IObjectDaos;
using CSP.Dao.IObjectDaos.CSP;
using CSP.Model.CSP;
using CSP.DataAccess;

namespace CSP.Dao.ObjectDaos.CSP
{
    public class AgeGroupDao : CSPCommonDao, IAgeGroupDao
    {
        public AgeGroupDao(CSPContext context, bool isTransaction = false)
            : base(context, isTransaction)
        { }

        public ICollection<Model.CSP.AgeGroup> FindAll()
        {
            return _context.AgeGroups.ToArray();
        }

        public Model.CSP.AgeGroup GetDataById(int id)
        {
            return _context.AgeGroups.FirstOrDefault(a => a.id == id);
        }

        public ICollection<Model.CSP.AgeGroup> GeDatatByIds(int[] Ids)
        {
            return _context.AgeGroups.Where(a => Ids.Contains(a.id)).ToArray();
        }

        public void Add(Model.CSP.AgeGroup obj)
        {
            _context.AgeGroups.Add(obj);
            _context.SaveChanges();
        }

        public void Update(Model.CSP.AgeGroup obj)
        {
            AgeGroup ageGroup = GetDataById(obj.id);
            if (ageGroup != null)
            {
                ageGroup = obj;
            }
            _context.SaveChanges();
        }

        public AgeGroup DeleteById(int id)
        {
            AgeGroup ageGroup = GetDataById(id);
            _context.AgeGroups.Remove(ageGroup);
            _context.SaveChanges();
            return ageGroup;
        }
    }
}
